package cn.lzb.book.server.api.book;

import cn.lzb.book.server.entity.BaseResult;
import cn.lzb.book.server.entity.dto.CategoryInfo;
import cn.lzb.book.server.entity.vo.CategoryVo;
import cn.lzb.book.server.service.ICategoryService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类编辑
 *
 * @author liuzhibo
 * @date 2024/8/28 16:58
 **/
@Api(tags = "分类管理接口")
@RestController
@RequestMapping("/category")
public class CategoryApi {

    public final ICategoryService categoryService;

    public CategoryApi(ICategoryService categoryService) {
        this.categoryService = categoryService;
    }

    public void addCategory(CategoryInfo categoryInfo) {
        //TODO 这里就不做实现了，每次新增分类根据时判定是否存在父级别分类code，如果存在则本次新增分类的code为 父code_子code，然后进行唯一性判定
    }

    public void updateCategory() {
        //TODO
    }

    public void deleteCategory() {
        //TODO
    }


    @GetMapping("/query/category")
    public BaseResult<CategoryVo> queryCategory(@RequestParam String categoryCode) {
        CategoryVo categoryVo = categoryService.queryCategory(categoryCode);
        return BaseResult.success(categoryVo);
    }

    @GetMapping("/query/category/all")
    public BaseResult<List<CategoryVo>> queryAllCategory() {
        List<CategoryVo> categoryVos = categoryService.queryAllCategory();
        return BaseResult.success(categoryVos);
    }
}
